# borrowed from util.lst of sanderson.com/util.zip
def transpose(l):
    "[[a]]->[[a]]--transpose a matrix made of lists"
    if not l: # this is needed for Python 2.3, in which `zip()` fails.
        return []
    else:
        return zip(*l)
def partition(f, l):
    "(a->bool)*[a]->([a]*[a])--divide l in two using f and return both halves"
    yes = []; no = []
    for x in l:
        if f(x):
            yes.append(x)
        else:
            no.append(x)
    return yes, no
# found on http://www.daniweb.com/code/showsnippet.php?codeid=459
def permutate(seq):
    """permutate a sequence and return a list of the permutations"""
    if not seq:
        return [seq]  # is an empty sequence

    else:
        temp = []
        for k in range(len(seq)):
            #part = seq[:k] + seq[k+1:]

            for m in permutate(seq[:k] + seq[k+1:]):
                temp.append(seq[k:k+1] + m)

        return temp
